import React from 'react'
import { useDispatch, useSelector } from 'react-redux';
import { RootState ,AppDispatch } from '../store/store';
import { decrement, increment,incrementAsync } from '../store/reducer/reducer';
function Count() {
   const count = useSelector((state: RootState) => state.counter.value)
  const dispatch :AppDispatch= useDispatch()

  return (
    <div>
      {/* 点击+1 -1 立即执行 这个是同步 */}
      <button onClick={() => {           
        dispatch(increment())
      }}>+1</button>
      <h1>{count}</h1>
      <button
        onClick={() => {
          dispatch(decrement())
        }}>-1</button>

     {/* 点击+3等待2秒这个是异步 */}
        <button  onClick={()=>{
          dispatch(incrementAsync())
        }}>+3</button>
    </div>
  )
}

export default Count
              